package com.example.gokchinesefoodmapmcdev.util;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 使用google中的Cache类，创建一个Cache对象，将验证码保存进去，而取代使用session
 * expireAfterAccess设置有效时间为2分钟
 */
@Component
public class CacheUtils {

    Cache<String, String> localCache;

    public CacheUtils() {
        this.localCache
                = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(2, TimeUnit.MINUTES).build();
    }

    public Cache<String, String> getLocalCache() {
        return localCache;
    }


}
